import { defineStore } from 'pinia';

interface DictItem {
  label: string;
  value: string | number;
}
interface DictsState {
  // 查询过的dicts对象
  dictSession: Record<string, DictItem[]> | null;
}

export const userDictsStore = defineStore('dicts-store', {
  state: (): DictsState => ({
    dictSession: {}
  }),
  getters: {
    getStoreDict: state => (key: string) => {
      if (state.dictSession) return state.dictSession[key];
      return null;
    }
  },
  actions: {
    updateDicts(rowItem: Record<string, DictItem[]>) {
      if (!rowItem) return;

      const key = Object.keys(rowItem)[0];
      if (!this.dictSession) this.dictSession = {};
      this.dictSession[key] = rowItem[key];
    }
  }
});
